import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import Home from '../components/home/Index.vue'
import Category from '../components/category/Index.vue'
import Discover from '../components/discover/Index.vue'
import My from '../components/my/Index.vue'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/home',
      name: 'home',
      component: HomeView
    },
    {
      path: '/xiangmu',
      // name:'home',  
      component: () => import('../Appapp.vue'),
      children: [
        {

          path: 'home',
          name: 'home',
          component: Home
        },
        {
          path: 'category',
          name: 'category',
          component: Category
        },
        {
          path: 'discover',
          name: 'discover',
          component: Discover
        },
        {
          path: 'my',
          name: 'my',
          component: My
        },
      ]
    },
    {
      path: '/about',
      name: 'about',
      component: () => import('../views/AboutView.vue')
    },

    {
      path: '/mynavtion',
      name: 'mynavtion',
      component: () => import('../components/my/Naviton.vue')
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('../components/login/index.vue')
    }
  ]
})


router.beforeEach((to, from, next) => {
  if (to.path == "/login") {
    next()
  } else {
    if (localStorage.token) {
      next()
    } else {
      next("/login")
    }
  }
})

export default router
